package humynn.sbd
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	
	import humynn.engine.Control;
	import humynn.engine.Input;
	import humynn.engine.Renderer;

	/**
	 * The timer bar for the waves of stink bugs.
	 */
	public class TimerBar extends Control
	{
		private var _frameFile:String;
		private var _barScale:Point;
		
		public function TimerBar()
		{
			super();
			
			_imageFile = "timerbar.png";
			_frameFile = "healthframe.png";
			_barScale = new Point(100, 1);
		}
		
		/**
		 * Updates the progress as the wave goes on.
		 * 
		 * @param e TimerEvent information.
		 */
		public function updateProgress(e:TimerEvent):void
		{
			if(e == null)
			{
				_barScale.x = 0;
				return;
			}
			
			_barScale.x = 100 - (e.target.currentCount / e.target.repeatCount) * 100;
		}
		
		/**
		 * Draws the timer bar and frame.
		 * 
		 * @param renderer The renderer to draw to.
		 */
		public override function draw(renderer:Renderer):void
		{
			renderer.draw(_frameFile, 0, 0, x, y);
			renderer.draw(_imageFile, 0, 0, x + 2, y + 2, _barScale);
		}
	}
}